package vivek.project.pocketmoney.common.controls
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	import mx.containers.Panel;
	import mx.controls.Image;
	import mx.core.IToolTip;
	import mx.effects.Resize;
	import mx.effects.Rotate;
	import mx.events.ToolTipEvent;
	import mx.managers.PopUpManager;
	import mx.managers.ToolTipManager;

	public class ModulePanel extends Panel
	{
		private var _helpControlId:String="";
		private var _moduleId:String="";
		//[Embed("assets/icons/panel_show.gif")]
		public var hMaximizeIcon:Class;
		private var _export:Boolean=false;
		private var _exportFunction:Function;

		public function ModulePanel()
		{
			super();
			_minimizer.addEventListener(MouseEvent.CLICK, showHelpWindow);
			_minimizer.addEventListener(ToolTipEvent.TOOL_TIP_SHOW, showHelp);
			//_minimizer.setStyle("icon", helpIcon);
			_minimizer.addEventListener(MouseEvent.MOUSE_OVER, showHelp);
			_minimizer.addEventListener(MouseEvent.MOUSE_OUT, destroyBigTip); //_hminimizer.addEventListener(MouseEvent.CLICK,hminimize)
			if (_exportFunction !== null)
				_exporter.addEventListener(MouseEvent.CLICK, _exportFunction);
		}

		public function set helpControlId(helpId:String):void
		{
			_helpControlId=helpId;
		}
		;

		public function set exportFunction(exportFunction:Function):void
		{
			_exportFunction=exportFunction;
		}

		public function get helpControlId():String
		{
			return _helpControlId
		}
		;

		public function set showExport(show:Boolean):void
		{
			_export=show
		}
		;

		public function get showExport():Boolean
		{
			return _export;
		}
		;

		public function set moduleId(helpId:String):void
		{
			_moduleId=helpId
		}

		public function get moduleID():String
		{
			return _moduleId
		}
		//[Embed("assets/icons/export_32.png")]
		private var _exportIcon:Class;
		//[Embed("assets/icons/help_32.png")]
		private var helpIcon:Class;
		private var _exporter:Image=new Image();
		private var _minimizer:Image=new Image();
		private var _oldHeight:int=30;
		private var _oldWidth:int=DEFAULT_MEASURED_MIN_WIDTH;
		private var _oldX:int=x;
		private var _oldY:int=y;
		private var _resizerEffect:Resize=new Resize();
		private var myTextFormat:TextFormat=new TextFormat();
		private var rotate:Rotate=new Rotate(this);
		public var myTip:IToolTip;

		override protected function createChildren():void
		{
			super.createChildren();
			_minimizer.source=helpIcon;
			_exporter.source=_exportIcon;
			_minimizer.autoLoad=true
			_exporter.autoLoad=true
			//if (event.stage
			super.titleBar.addChild(_exporter);
			super.titleBar.addChild(_minimizer);
			//super.titleBar.addChild(_hminimizer);
		}

		private function showHelp(event:MouseEvent):void
		{
			var help:String=resourceManager.getString(_moduleId, _helpControlId);
			myTip=ToolTipManager.createToolTip(help, event.stageX, event.stageY);
			myTip.x=event.stageX - myTip.width
			//myTip=ToolTipManager.createToolTip(help, event.stageX, event.stageY);
		}

		private function showHelpWindow(event:MouseEvent):void
		{
			var help:String=resourceManager.getString(_moduleId, _helpControlId);
			var helpme:ToolTipControl=PopUpManager.createPopUp(this, ToolTipControl, true) as ToolTipControl
			PopUpManager.centerPopUp(helpme) //helpme.helpControlId=_helpControlId
			helpme.helpText=help
			//var pop1:AddTransactionsModule=PopUpManager.createPopUp(this, AddTransactionsModule, true) as AddTransactionsModule;
			//myTip=ToolTipManager.createToolTip(help, event.stageX, event.stageY);
		}

		private function destroyBigTip(event:Event):void
		{
			ToolTipManager.destroyToolTip(myTip);
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			_minimizer.x=super.titleBar.width - 30;
			_exporter.x=super.titleBar.width - 50;
			//_hminimizer.x=super.titleBar.width-35;
			_exporter.y=0;
			_minimizer.y=0;
			_exporter.width=16;
			_exporter.height=16;
			_minimizer.width=24;
			_minimizer.height=24;
			_exporter.visible=showExport;
			_exporter.includeInLayout=showExport;
			if (_exportFunction !== null)
				_exporter.addEventListener(MouseEvent.CLICK, _exportFunction);

		}
	}
}